package com.brainhealth.customer.handle;

import org.redisson.api.RBlockingDeque;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author wolong
 * @description:
 */
@Component
public class RedissionDelayHandle
{

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private RedissionService redissionService;

    @PostConstruct
    public void listener() {
        new Thread(()->{
            while (true){
                RBlockingDeque<String> blockingDeque = redissonClient.getBlockingDeque("async-hand-msg");
                String msg  = null;
                try {
                    msg = blockingDeque.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                redissionService.handleWLClueAdd(msg);
            }
        }).start();


        new Thread(()->{
            while (true){
                RBlockingDeque<String> scoreRechargeBlockingDeque = redissonClient.getBlockingDeque("async-hand-score-recharge-msg");
                String orderId  = null;
                try {
                    orderId = scoreRechargeBlockingDeque.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                redissionService.handleScoreOrderClueAdd(orderId);
            }
        }).start();
    }
}
